//
//  UITextField+Safe.m
//  niuguwang
//
//  Created by BrightLi on 2021/1/2.
//  Copyright © 2021 taojinzhe. All rights reserved.
//

#import "UITextField+Safe.h"
#import "YMSafeUtil.h"

@implementation UIView(Safe)

+ (void) safe_fixed
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        [YMSafeUtil swizzleInstance:[self class]
                              sel1:@selector(setHidden:)
                              sel2:@selector(safe_setHidden:)];
        [YMSafeUtil swizzleInstance:[self class]
                              sel1:@selector(setFrame:)
                              sel2:@selector(safe_setFrame:)];
    });
}

- (void) safe_setFrame:(CGRect)frame
{
    if(frame.size.width>[[SFitUtil mainScreen] bounds].size.width){
        if(self.tag == 1973){
            NSLog(@"?");
        }
    }
    [self safe_setFrame:frame];
}

- (void) safe_setHidden:(BOOL)hidden
{
    [self safe_setHidden:hidden];
}

@end

@implementation UIControl(Safe)

+ (void) safe_fixed
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        [YMSafeUtil swizzleInstance:[self class]
                              sel1:@selector(setSelected:)
                              sel2:@selector(safe_setSelected:)];
    });
}

- (void) safe_setSelected:(BOOL)selected
{
    [self safe_setSelected:selected];
}

@end

@implementation UITextField(Safe)

static const void *navStackLastChangedTimeKey=&navStackLastChangedTimeKey;

+ (void) safe_fixed
{
#if TARGET_IPHONE_SIMULATOR
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        [YMSafeUtil swizzleInstance:[self class]
                  sel1:@selector(setSecureTextEntry:)
                  sel2:@selector(safe_setSecureTextEntry:)];
    });
#endif
}

-(void) safe_setSecureTextEntry:(BOOL)secureTextEntry
{
    [self safe_setSecureTextEntry:secureTextEntry];
    if (@available(iOS 11.0, *)) {
        self.textContentType = UITextContentTypeName;
    }
}

@end

